﻿/*
 
    This file is part of AnkhBG.

    AnkhBG is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AnkhBG is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with AnkhBG.  If not, see <http://www.gnu.org/licenses/>.
 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Glider.Common.Objects;

namespace AnkhBG
{
    public partial class MainForm : Form
    {
        //public static ConfigForm SaveSettings = SaveSettings.Load();
        GSpellTimer StartStopCD = new GSpellTimer(2500); // to evade doubleclick-mistakes

        public MainForm()
        {
            InitializeComponent();
        }

        public void StartStopButton_Click(object sender, EventArgs e)
        {
            if (StartStopCD.IsReady)
            {
                if (!GContext.Main.IsAttached && !Main.Instance.running) // don't start if not attached
                    Main.Instance.Window.LogError("Can't start because Glider is not attached.");
                else
                    Main.Instance.running = !Main.Instance.running;

                StartStopCD.Reset();
            }
        }

        public void StatsButton_Click(object sender, EventArgs e)
        {
            Main.Instance.Stats.ShowWindow();
        }

        public void ConfigButton_Click(object sender, EventArgs e)
        {
            Main.Instance.Config.ShowWindow();
        }

        public void Log(string logText)
        {
            LogBox.Items.Add(" [" + DateTime.Now.ToString("HH:mm:ss") + "]  " + logText);

            // auto-scroll
            int itemsPerPage = (int)(LogBox.Height / LogBox.ItemHeight);
            LogBox.TopIndex = LogBox.Items.Count - itemsPerPage;
        }

        public void LogError(string logText)
        {
            Log("Error: " + logText);

            this.StatusText.Image = global::AnkhBG.Properties.Resources.error;
            this.StatusText.Text = "Error!";
        }
    }
}
